library(gapminder)
library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.0 ✔ purrr 0.3.0
## ✔ tibble 2.0.1 ✔ dplyr 0.8.0.1
## ✔ tidyr 0.8.2 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ─────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(anchors)
## Loading required package: rgenoud
## ## rgenoud (Version 5.8-3.0, Build Date: 2019-01-22)
## ## See http://sekhon.berkeley.edu/rgenoud for additional documentation.
## ## Please cite software as:
## ## Walter Mebane, Jr. and Jasjeet S. Sekhon. 2011.
## ## ``Genetic Optimization Using Derivatives: The rgenoud package for R.''
## ## Journal of Statistical Software, 42(11): 1-26.
## ##
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
##
## ## anchors (Version 3.0-8, Build Date: 2014-02-24)
## ## See http://wand.stanford.edu/anchors for additional documentation and support.
library(gganimate)
library(gifski)
library(png)
moving <- gapminder %>%
mutate(continent = fct_collapse(continent, Asia = c("Asia", "Oceania"))) %>%
filter(continent %in% c("Americas", "Africa", "Asia")) %>%
mutate(continent = fct_relevel(continent, c("America", "Africa", "Asia"))) %>%
group_by(continent)
## Warning: Unknown levels in `f`: America
moving %>%
ggplot(aes(x = gdpPercap, y = lifeExp, size = pop)) +
facet_wrap(~continent) +
scale_x_log10(breaks = c(1000, 10000),
labels = c("$1000", "$10,000")) +
geom_point(alpha = .5, show.legend = FALSE, aes(color = country)) +
scale_color_manual(values = country_colors) +
labs(x = "GDP Per Capita",
y = "Life Expectancy") +
ggtitle("The World Gets Better Every Year: {frame_time}") +
transition_time(year) +
ease_aes()
